function moveZeroes(nums) {
    if (!nums || nums.length === 0) return
    let i = 0
    for (let index = 0; index < nums.length; index++) {
        if (nums[index] !== 0) {
            nums[i] = nums[index]
            i++
        }
    }
    while(i < nums.length) {
        nums[i] = 0
        i++
    }
    return nums
}

const nums = [0,1,0,3,12]

console.log(moveZeroes(nums))